home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / HyperCard / Shifting Priorities / card_2988.txt < prev    next >
Text File  |  1994-05-01  |  13KB  |  334 lines

  1. -- card: 2988 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2679
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 25
  10. -- high flags: 0007
  11. -- rect: left=27 top=28 right=324 bottom=484
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 16
  16. -- text size: 10
  17. -- style flags: 0
  18. -- line height: 13
  19. -- part name: Priorities
  20. ----- HyperTalk script -----
  21. --                       ShiftingPriorities
  22. --
  23. -- A self-contained field script to easily rearrange lines in fields:
  24. --
  25. --     Shift-click near any corner to resize.
  26. --     Shift-click near the center to relocate.
  27. --     Option-click to change text size.
  28. --     Command-click to modify text attributes.
  29. --     Click and hold on a line to select and move it.
  30. --     Single-click to open the field for editing.
  31. --
  32. -- This field must have its textLock and dontWrap properties set,
  33. -- and must be a scrolling field. Simple clone-and-go feature.
  34. --
  35. -- ¬© 1992 Douglas Parker & Maccyx. All rights reserved.
  36. --
  37. -- This script may be circulated freely, provided these comments
  38. -- remain unaltered.
  39. --
  40. ----------------------------------------------------------------------
  41. on mouseDown
  42.   if the optionKey is down then
  43.     put "*" into it -- a dummy value
  44.     repeat until it is a number or theResult is "Cancel"
  45.       ask "Change the text to which point size?" with the textSize of me
  46.       put the result into theResult
  47.       put it into theIt
  48.  
  49.       -- make sure it's a valid response
  50.  
  51.       if it is a number and it is not empty and theResult is not "Cancel" then
  52.         set the textSize of me to it
  53.       else if theResult is not "Cancel" then
  54.         beep
  55.         answer "That is not a number" with "OK"
  56.         -- put the result into it
  57.       end if
  58.     end repeat
  59.   else if the shiftKey is down then
  60.  
  61.     -- we're going to move or rearrange things here
  62.  
  63.     put item one of the mouseLoc into xMouse
  64.     put item two of the mouseLoc into yMouse
  65.  
  66.     put item one of the loc of me into xField
  67.     put item two of the loc of me into yField
  68.  
  69.     -- divide the field into a 3x3 matrix, then test for
  70.     -- the mouse being in the center region.
  71.     if (abs(xField - xMouse) < the width of me/6) and (abs(yField - yMouse) < the width of me/6) then
  72.       repeat until the mouse is up
  73.         set the loc of me to the mouseLoc -- move me around
  74.       end repeat
  75.     else
  76.       put the width of me into myWidth
  77.       put the height of me into myHeight
  78.       -- similarly, divide the field into a 6x6 matrix. If the
  79.       -- mouse is down inside the corner 1/36th area, then resize
  80.       -- Hmm, now why did he choose 1/36th?
  81.       if (abs(xField - xMouse) > myWidth/2 - myWidth/6) and (abs(yField - yMouse) > myHeight/2 - myHeight/6) then
  82.         put the rect of me into theOriginalRect
  83.         repeat until the mouse is up -- resize me by the corners
  84.           if item 1 of the mouseLoc > item 1 of the loc of me and item 2 of the mouseLoc < item 2 of the loc of me then
  85.             -- quadrant 1 top right
  86.             repeat until the mouse is up
  87.               put the rect of me into newRect
  88.               put item one of the mouseLoc into item 3 of newRect
  89.               put item two of the mouseLoc into item 2 of newRect
  90.               set the rect of me to newRect
  91.             end repeat
  92.           else if item 1 of the mouseLoc < item 1 of the loc of me and item 2 of the mouseLoc < item 2 of the loc of me then
  93.             --quadrant 2 top left
  94.             repeat until the mouse is up
  95.               put the rect of me into newRect
  96.               put item one of the mouseLoc into item 1 of newRect
  97.               put item two of the mouseLoc into item 2 of newRect
  98.               set the rect of me to newRect
  99.             end repeat
  100.           else if item 1 of the mouseLoc < item 1 of the loc of me and item 2 of the mouseLoc > item 2 of the loc of me then
  101.             -- quadrant 3 bottom left
  102.             repeat until the mouse is up
  103.               put the rect of me into newRect
  104.               put item one of the mouseLoc into item 1 of newRect
  105.               put item two of the mouseLoc into item 4 of newRect
  106.               set the rect of me to newRect
  107.             end repeat
  108.           else
  109.             -- quadrant 4 bottom right
  110.             repeat until the mouse is up
  111.               put the rect of me into newRect
  112.               put item one of the mouseLoc into item 3 of newRect
  113.               put item two of the mouseLoc into item 4 of newRect
  114.               set the rect of me to newRect
  115.             end repeat
  116.           end if
  117.         end repeat
  118.         -- but you can't make it too small...
  119.         if the height of me ‚⧠30 or the width of me ‚⧠60 then
  120.           beep
  121.           set the rect of me to theOriginalRect
  122.         end if
  123.       end if
  124.     end if
  125.   else if the commandKey is down then
  126.     -- bring up the text attribute dialog box...
  127.     lock Screen
  128.     set cursor to watch
  129.     put the userlevel into theUserlevel
  130.     set the userlevel to 5
  131.     choose field tool
  132.     click at the loc of me
  133.     type "t" with commandKey
  134.     set the userlevel to theUserlevel
  135.     choose browse tool
  136.     unlock Screen
  137.     set cursor to hand
  138.   else
  139.     global lastTick
  140.     put the ticks into lastTick
  141.   end if
  142.   pass mouseDown
  143. end mouseDown
  144.  
  145. on mouseStillDown
  146.   global lastMSD, lastTick
  147.   put the ticks into thisMSD
  148.   put word 2 of the clickLine into theClickLine
  149.   put the number of lines of me into theLineCount
  150.  
  151.   -- The mouse*Up* handler for this field uses a "click at" command.
  152.   -- Side effects of the click at command include a "mouseDown",
  153.   -- ten "mouseStillDown"s, and "mouseUp" system messages to be
  154.   -- issued--as if the mouse is being clicked very slowly. These
  155.   -- unwanted mouseStillDowns are intercepted, but discarded by
  156.   -- setting the value of N on the line
  157.   --            if thisMSD - lastMSD ‚â• N then
  158.   -- to some value shorter than the repeating execution time
  159.   -- of the user's mouseStillDown script, yet large enough that
  160.   -- the unwanted mouseStillDowns are filtered out.
  161.   --
  162.   -- The line also prevents execution of the remaining part of the
  163.   -- handler if the user clicks in white space beyond the last line.
  164.  
  165.   if (thisMSD - lastMSD ‚â• 60) and (theClickLine ‚⧠theLineCount) then
  166.     put the ticks into lastMSD -- for next time
  167.     put line word two of the clickLine of me into holdLine -- preprocessing
  168.     put the scroll of me into theScroll -- I'm going to lose the scroll soon
  169.  
  170.     -- this section calculates the lineHeight in pixels, not points,
  171.     -- and sets some constants to speed up the repeat loop
  172.  
  173.     lock Screen -- don't want 'em to see the fields shifting...
  174.     put the top of me into theTopOfMe -- preprocessing
  175.  
  176.     if the wideMargins of me then -- evaluates to if true then
  177.       put 4 into marginWidth -- all textHeights use a wide margin of 4
  178.     else
  179.       put 0 into marginWidth
  180.     end if
  181.  
  182.     select char 1 to 0 of line 1 of me -- this can modify the scroll
  183.     put item 2 of the selectedLoc - theTopOfMe - marginWidth - 1 into thePixelHeight -- all to find out the pixel height per line.
  184.     --             -- It can vary.
  185.  
  186.     select empty -- hide the text cursor
  187.  
  188.     -- this resets the original scroll in case the select line changed it
  189.  
  190.     set scroll of me to theScroll
  191.     unlock Screen
  192.  
  193.     -- making theDragLine equal to theClickLine won't move it
  194.     -- the first time through the repeat
  195.  
  196.     put min(theLineCount,theClickLine) into theDragLine -- theDragLine needs a value
  197.     put (the top of me + marginWidth + 1) into theFactor -- preprocessing
  198.  
  199.     -- If the mouse is held down just long enough to enter this hander
  200.     -- AND just long enough to go through the repeat loop once, there
  201.     -- may be too much time between the user's lastTick from the
  202.     -- mouseDown and the execution of the mouseUp handler to place the
  203.     -- I-beam when that is the intention. This next
  204.     -- line is here *just in case* this happens. It also smooths out
  205.     -- the execution of the I-beam insertion in the field.
  206.  
  207.     put the ticks into lastTick
  208.  
  209.     -- This next two lines can be moved inside the repeat loop.
  210.     -- If they are moved inside the repeat, the cursor won't change
  211.     -- until the text is *really* ready to move as the user holds
  212.     -- the mouse down. One side effect of this will be a flashing
  213.     -- cursor as the set cursor command is repeatedly executed.
  214.     -- If-then-elses could be used to assure one-shot operation,
  215.     -- but would slow down the loop speed. NB: The loop has to be
  216.     -- optimized for speed to make the screen moves follow the
  217.     -- mouse closely.
  218.  
  219.     set cursor to arrow -- prepare to move
  220.     set the textStyle of line word two of the clickLine of me to bold
  221.     repeat while the mouse is down
  222.       wait for 5 ticks -- keep from selecting adjacent lines every time
  223.  
  224.       -- this follows the mouse around the screen, calculating line numbers
  225.  
  226.       put trunc((item two of the mouseLoc + theScroll - theFactor)/ (thePixelHeight)) + 1 into theDragLine
  227.       put max(1,min(theLineCount,theDragLine)) into theDragLine
  228.       if theClickLine ‚↠theDragLine and theClickLine ‚⧠theLineCount then
  229.  
  230.         -- theClickLine is the destination
  231.         -- theDragLine is the source
  232.  
  233.         lock Screen -- make it pretty!
  234.         delete line theClickLine of me
  235.         put holdLine & return before line theDragLine of me
  236.  
  237.         -- Beyon the top or bottom? Scroll the field appropriately.
  238.  
  239.         if item 2 of the mouseLoc ‚â• the bottom of me then
  240.           put theScroll + thePixelHeight into theScroll
  241.         else if item 2 of the mouseLoc ‚⧠the top of me then
  242.           put theScroll - thePixelHeight into theScroll
  243.         end if
  244.         set scroll of me to theScroll
  245.         set the textStyle of line theDragLine of me to bold
  246.  
  247.         -- use a visual effect in the next line to give
  248.         -- a different feel & look.
  249.  
  250.         unlock Screen -- with dissolve -- aah! that feels better...
  251.       end if
  252.       put theDragLine into theClickLine
  253.     end repeat
  254.     set the textStyle of line theClickLine of me to plain
  255.   end if
  256.   pass mouseStillDown
  257. end mouseStillDown
  258.  
  259. on closeField
  260.  
  261.   -- Get rid of unnecessary null lines at the end of the field.
  262.   -- The user can't see them and usually creates plenty of them
  263.   -- as they click once within the white space at the end of the
  264.   -- field.
  265.  
  266.   repeat while the last line of me is empty and the number of lines of me ‚â• 1
  267.     delete the last line of me
  268.   end repeat
  269.   set the lockText of me to true
  270.   pass closeField
  271. end closeField
  272.  
  273. on exitField
  274.  
  275.   -- Get rid of unnecessary null lines at the end of the field.
  276.   -- The user can't see them and usually creates plenty of them
  277.   -- as they click once within the white space at the end of the
  278.   -- field.
  279.  
  280.   repeat while the last line of me is empty and the number of lines of me ‚â• 1
  281.     delete the last line of me
  282.   end repeat
  283.   set the lockText of me to true
  284.   send "closeField" to me
  285.   pass exitField
  286. end exitField
  287.  
  288. on mouseUp
  289.   global lastTick
  290.  
  291.   -- Your value may vary. 45 ticks works for an SE/30. The
  292.   -- difference measures the time between the mouseDown and
  293.   -- this mouseUp, --or-- between the first iteration of the
  294.   -- mouseStillDown repeat loop and this mouseUp.
  295.  
  296.   -- Too many single clicks make the I-beam appear? Decrease the value.
  297.   -- Not enough single clicks bring the I-beam? Increase the value.
  298.  
  299.   if (the ticks - lastTick ‚⧠45) then
  300.     set the lockText of me to false
  301.     click at the clickLoc
  302.   end if
  303.   put the ticks into lastTick
  304.   pass mouseUp
  305. end mouseUp
  306.  
  307.  
  308.  
  309.  
  310. -- part contents for card part 1
  311. ----- text -----
  312. Press Tab, press Enter, or click outside the field to get back the browse tool.
  313. Add a period to the end of this line
  314. <Return> works within the field. It doesn't work like Tab or Enter.
  315. Change the text size to 12 point‚Äî(option-click with the browse tool)
  316. Try to change text size to an erroneous value!
  317. The field has to be a scrolling field.
  318. Remember to set the ‚ÄúlockText‚Äù of any new fields you create.
  319. Be sure to set the ‚ÄúDon't Wrap‚Äù attribute -- or else! :-)
  320. Command-click with the browse tool to change text characteristics.
  321. Try to double-click on a word.
  322. Hold the mouse button down on this line. Drag it around the field.
  323. The best double click technique is: single-click (pause) single-click.
  324. Shift-click near the *center* to move the field.
  325. Shift-click near the corners to resize the field.
  326. Resize too small and you'll get a beep and the field size will restore.
  327. Put lots o‚Äô lines in the field and try to drag beyond the top or the bottom edge.
  328. Scrolling works properly!
  329. Happy Scripting. Drop me a note if you like it.
  330. Douglas Parker
  331. 45090 Elmhurst Ct.
  332. Utica, MI  48317-4991
  333. Freeware.
  334.